package com.zhentao.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类 - 配置静态资源访问
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    
    @Value("${avatar.upload.path}")
    private String uploadPath;
    
    /**
     * 配置静态资源映射
     * 将 /avatars/** 映射到本地上传目录
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置头像访问路径
        registry.addResourceHandler("/avatars/**")
                .addResourceLocations("file:" + uploadPath);
        
        System.out.println("=== 静态资源配置 ===");
        System.out.println("头像访问路径: /avatars/**");
        System.out.println("本地存储路径: file:" + uploadPath);
        System.out.println("示例URL: http://localhost:1005/avatars/avatar_1_xxx.jpg");
    }
}
